# -*- coding: utf-8 -*-
from framework.model.base_model import Log
from .DingTalkLogic import DingTalkLogic
from framework.app import db
import json


class CommonLogic(object):
    @staticmethod
    def writeLog(pusher_webhook, params, status, err_msg):
        log = Log()
        log.pusher_id = pusher_webhook.pusher_id
        log.pusher_webhook_id = pusher_webhook.id
        log.address_name = pusher_webhook.address_name
        log.text = params['msg']
        log.msg_type = params['msg_type'] if 'msg_type' in params else 1
        log.data = json.dumps(params)
        log.status = status
        log.error_msg = err_msg
        db.session.add(log)
        db.session.commit()
        